package com.coder.chen.slidingmenu.view;

import com.coder.chen.slidingmenu.view.SlidingView.OnScrollCloseListener;
import com.coder.chen.slidingmenu.view.SlidingView.OnScrollOpenListener;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;

public class SlidingMenu extends RelativeLayout {
	private SlidingView mSlidingView;
	private View mMenuView;
	private View mDetailView;

	// 中间页面的保留宽度
	private int alignScreenWidth;

	public SlidingMenu(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public SlidingMenu(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public SlidingMenu(Context context) {
		super(context);
	}

	/**
	 * 设置中间页面的保留宽度
	 * 
	 * @param alignScreenWidth
	 */
	public void setAlignScreenWidth(int alignScreenWidth) {
		this.alignScreenWidth = alignScreenWidth;
	}

	public void addViews(View leftView, View centerView, View rightView) {
		setLeftView(leftView);
		setRightView(rightView);
		setCenterView(centerView);
	}

	/**
	 * 设置中间页面的View
	 * 
	 * @param centerView
	 *            传入的布局
	 */
	public void setCenterView(View centerView) {
		LayoutParams aboveParams = new LayoutParams(LayoutParams.MATCH_PARENT,
				LayoutParams.MATCH_PARENT);
		mSlidingView = new SlidingView(getContext());
		addView(mSlidingView, aboveParams);

		mSlidingView.setView(centerView);
		mSlidingView.invalidate();

		mSlidingView.setMenuView(mMenuView);
		mSlidingView.setDetailView(mDetailView);
	}

	/**
	 * 设置左侧的View
	 * 
	 * @param leftView
	 *            传入的布局
	 */
	public void setLeftView(View leftView) {
		LayoutParams behindParams = new LayoutParams(alignScreenWidth,
				LayoutParams.MATCH_PARENT);
		addView(leftView, behindParams);
		mMenuView = leftView;

	}

	/**
	 * 设置右侧的View
	 * 
	 * @param rightView
	 *            传入的布局
	 */
	public void setRightView(View rightView) {
		LayoutParams behindParams = new LayoutParams(alignScreenWidth,
				LayoutParams.MATCH_PARENT);
		behindParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
		addView(rightView, behindParams);
		mDetailView = rightView;
	}

	public void showLeftView() {
		mSlidingView.showLeftView();
	}

	public void showRightView() {
		mSlidingView.showRightView();
	}

	public void showCenterView() {
		mSlidingView.showCenterView();
	}

	public void setOnScrollOpenListener(
			OnScrollOpenListener onScrollOpenListener) {
		mSlidingView.setOnScrollOpenListener(onScrollOpenListener);
	}

	public void setOnScrollCloseListener(
			OnScrollCloseListener onScrollCloseListener) {
		mSlidingView.setOnScrollCloseListener(onScrollCloseListener);
	}

}
